package sgi.message;

import sgi.client.SGIUserAccountMenuController;
import sgi.details_new.ImageDetails;
import sgi.misc.Image;
import sgi.user.User;
/**sets queries required for purchasing images*/
public class MessagePurchaseImage extends Message {

	private String qGetBalance;
	private String qSetBalance;
	private String qCheckAlreadyPurchasedImage;
	private String qCheckImagePackSubscription;
	private String qDecrementImagePackSubscription;
	private String qCheckAlreadyPurchasedSample;
	private String qCheckDataLayerSubscription;
	private boolean hasImagePackSubscription;
	private boolean purcahseComplete;
	private boolean insufficiantBalance;
	private boolean imageAlreadyPurchased;
	private boolean sampleAlreadyPurchased;
	private boolean hasCommerceSubscription;
	private boolean hasInfrastractureSubscription;
	private User user;
	private ImageDetails details;
	private int imageid;
	private float price;
	private float tariff;
	private byte[] blobAsBytes;
	private byte[] blobAsBytesCommerce;
	private byte[] blobAsBytesInfrastracture;
	private byte[] blobAsBytesCommerceInfrastracture;
	
	/**Constructor. Recieves imageID and sets the queries for modifying balance, checking for subscriptions and if sample/image were already purchased*/
	public MessagePurchaseImage(int imageid) {
		super("select image from tariff where pending = 1");
		this.imageid = imageid; 
		user = SGIUserAccountMenuController.getUser();
		setqGetBalance("select balance from customers where username = '"+user.getUsername()+"'");
		setqCheckImagePackSubscription("select COUNT(*) from image_pack_subscription where username = '" +user.getUsername()+"' and count > 0");
		setqDecrementImagePackSubscription("update image_pack_subscription set count = count-1 where username = '" +user.getUsername()+"'");
		setqCheckAlreadyPurchasedImage("select COUNT(*) from user_images where username = '" + user.getUsername() + "' and imageid = " + imageid + " and image = 1");
		setqCheckAlreadyPurchasedSample("select COUNT(*) from user_images where username = '" + user.getUsername() + "' and imageid = " + imageid + " and sample = 1");
		setqCheckDataLayerSubscription("select commerce,infrastracture from data_layer_subscription where username = '" + user.getUsername() + "' and pending=1");
	}

	public String getqGetBalance() {
		return qGetBalance;
	}

	public void setqGetBalance(String qGetBalance) {
		this.qGetBalance = qGetBalance;
	}

	public String getqSetBalance() {
		return qSetBalance;
	}

	public void setqSetBalance(String qSetBalance) {
		this.qSetBalance = qSetBalance;
	}

	public String getqCheckImagePackSubscription() {
		return qCheckImagePackSubscription;
	}

	public void setqCheckImagePackSubscription(
			String qCheckImagePackSubscription) {
		this.qCheckImagePackSubscription = qCheckImagePackSubscription;
	}

	public String getqDecrementImagePackSubscription() {
		return qDecrementImagePackSubscription;
	}

	public void setqDecrementImagePackSubscription(
			String qDecrementImagePackSubscription) {
		this.qDecrementImagePackSubscription = qDecrementImagePackSubscription;
	}

	public boolean isHasImagePackSubscription() {
		return hasImagePackSubscription;
	}

	public void setHasImagePackSubscription(boolean hasImagePackSubscription) {
		this.hasImagePackSubscription = hasImagePackSubscription;
	}

	public float getPrice() {
		return price;
	}

	public void setPrice(float d) {
		this.price = d;
	}

	public float getTariff() {
		return tariff;
	}

	public void setTariff(float f) {
		this.tariff = f;
	}

	public boolean isPurcahseComplete() {
		return purcahseComplete;
	}

	public void setPurcahseComplete(boolean purcahseComplete) {
		this.purcahseComplete = purcahseComplete;
	}
	
	public String getUsername()
	{
		return user.getUsername();
	}

	public int getImageid() {
		return imageid;
	}

	public void setImageid(int imageid) {
		this.imageid = imageid;
	}

	public String getqCheckAlreadyPurchasedImage() {
		return qCheckAlreadyPurchasedImage;
	}

	public void setqCheckAlreadyPurchasedImage(
			String qCheckAlreadyPurchasedImage) {
		this.qCheckAlreadyPurchasedImage = qCheckAlreadyPurchasedImage;
	}

	public boolean isInsufficiantBalance() {
		return insufficiantBalance;
	}

	public void setInsufficiantBalance(boolean insufficiantBalance) {
		this.insufficiantBalance = insufficiantBalance;
	}

	public boolean isImageAlreadyPurchased() {
		return imageAlreadyPurchased;
	}

	public void setImageAlreadyPurchased(boolean imageAlreadyPurchased) {
		this.imageAlreadyPurchased = imageAlreadyPurchased;
	}

	public byte[] getBlobAsBytes() {
		return blobAsBytes;
	}

	public void setBlobAsBytes(byte[] blobAsBytes) {
		this.blobAsBytes = blobAsBytes;
	}

	public String getqCheckAlreadyPurchasedSample() {
		return qCheckAlreadyPurchasedSample;
	}

	public void setqCheckAlreadyPurchasedSample(
			String qCheckAlreadyPurchasedSample) {
		this.qCheckAlreadyPurchasedSample = qCheckAlreadyPurchasedSample;
	}

	public boolean isSampleAlreadyPurchased() {
		return sampleAlreadyPurchased;
	}

	public void setSampleAlreadyPurchased(boolean sampleAlreadyPurchased) {
		this.sampleAlreadyPurchased = sampleAlreadyPurchased;
	}

	public ImageDetails getDetails() {
		return details;
	}

	public void setDetails(ImageDetails details) {
		this.details = details;
	}


	public String getqCheckDataLayerSubscription() {
		return qCheckDataLayerSubscription;
	}

	public void setqCheckDataLayerSubscription(
			String qCheckDataLayerSubscription) {
		this.qCheckDataLayerSubscription = qCheckDataLayerSubscription;
	}

	public boolean isHasInfrastractureSubscription() {
		return hasInfrastractureSubscription;
	}

	public void setHasInfrastractureSubscription(
			boolean hasInfrastractureSubscription) {
		this.hasInfrastractureSubscription = hasInfrastractureSubscription;
	}

	public boolean isHasCommerceSubscription() {
		return hasCommerceSubscription;
	}

	public void setHasCommerceSubscription(boolean hasCommerceSubscription) {
		this.hasCommerceSubscription = hasCommerceSubscription;
	}

	public byte[] getBlobAsBytesCommerce() {
		return blobAsBytesCommerce;
	}

	public void setBlobAsBytesCommerce(byte[] blobAsBytesCommerce) {
		this.blobAsBytesCommerce = blobAsBytesCommerce;
	}

	public byte[] getBlobAsBytesInfrastracture() {
		return blobAsBytesInfrastracture;
	}

	public void setBlobAsBytesInfrastracture(byte[] blobAsBytesInfrastracture) {
		this.blobAsBytesInfrastracture = blobAsBytesInfrastracture;
	}

	public byte[] getBlobAsBytesCommerceInfrastracture() {
		return blobAsBytesCommerceInfrastracture;
	}

	public void setBlobAsBytesCommerceInfrastracture(
			byte[] blobAsBytesCommerceInfrastracture) {
		this.blobAsBytesCommerceInfrastracture = blobAsBytesCommerceInfrastracture;
	}
	
}
